package graph_viewer.util;

import java.awt.*;
import java.awt.image.*;

import  graph_viewer.drawer.*;
import graph_viewer.structure.Node;
import graph_viewer.structure.Node_Position;

public class Drawer_Util{
	public static void main( String args[] ){
		String label	= "/usr/include/malloc.h";
		String parsed_label	= parse_label( label );

		Debug.println( " label is: " + label , 3 );
		Debug.println( " parsed_label is: " + parsed_label , 3 );
	}
	
	static public boolean is_normal_view( String view_status ){
		return view_status.equals( Drawer.NORMAL_VIEW );
	}

	static public boolean is_distorted_view( String view_status ){
		return view_status.equals( Drawer.DISTORTED_VIEW );
	}


	static public int get_text_height( Graphics g ){
		g.setFont(  Drawer.FONT );
		FontMetrics font_metrics = g.getFontMetrics();
		int text_height = font_metrics.getHeight();

		return text_height;
	}

	static public int get_text_width( String text, Graphics g ){
		g.setFont(  Drawer.FONT );
		FontMetrics font_metrics = g.getFontMetrics();
		int text_width		= font_metrics.stringWidth( text );

		return text_width;
	}
	
	//12/02/2004: temperally, assume the lable is one line.
	static public int get_label_height( Graphics g ){
		return get_text_height( g );
	}

	static public String get_displayed_label( Node a_node ){
		StringBuffer label	= new StringBuffer();
		//label.append(  a_node.get_label() );
		//label.append(  "_" );
		label.append( a_node.get_text() );

		return parse_label( label.toString() );	
	}

	static private String parse_label( String a_label ){
		String sep = "/";

		int index_of_sep = a_label.lastIndexOf( sep );	

		if ( index_of_sep < 0 ){
			return a_label;
		}else{
			String parsed_string	= a_label.substring( index_of_sep, a_label.length() );

			return ".." + parsed_string;
		}
	}
}
